/*  yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef UNIT_H
#define UNIT_H

#include "collections/optioncollection.h"

class Unit {
public:
    QString category;
    QString description;

    enum UnitFlag {
        NoFlags = 0x0,
        Hidden = 0x1,
        UsesParentSize = 0x2
    };
    Q_DECLARE_FLAGS(UnitFlags, UnitFlag)

    UnitFlags flags;

    QStringList allowedItems;
    QHash<QString, QString> properties;
    QHash<QString, QString> cells;
    OptionCollection options;
    CategoryDataHash itemLimits;

    QString getName() const;
    uint getMinimumSize() const;
    uint getMaximumSize() const;
    float getCost() const;

    void setName(const QString& name);
    void setMinimumSize(uint size);
    void setMaximumSize(uint size);
    void setCost(float newCost);

    Unit();
    Unit(const QString& category, const QString& name, const QString& description, float cost,
         UnitFlags flags, uint minimumSize, uint maximumSize, const CategoryDataHash &itemLimits,
         const QStringList &allowedItems, const QHash<QString, QString> &properties,
         const OptionCollection &options, const QHash<QString, QString> &cells);

private:
    QString name;

    uint minimumSize;
    uint maximumSize;

    float cost;
};

inline QString Unit::getName() const {
    return name;
}

inline uint Unit::getMinimumSize() const {
    return minimumSize;
}

inline uint Unit::getMaximumSize() const {
    return maximumSize;
}

inline float Unit::getCost() const {
    return cost;
}

inline void Unit::setName(const QString &name) {
    this->name = GameStructs::getValidName(name);
}

inline void Unit::setMinimumSize(uint size) {
    minimumSize = size > 30000 ? 30000 : size;
}

inline void Unit::setMaximumSize(uint size) {
    maximumSize = size > 30000 ? 30000 : size;
}

inline void Unit::setCost(float newCost) {
    cost = (newCost <= 10000) ? (newCost >= 0 ? newCost : 0) : 10000;
}

#endif // UNIT_H
